//auto.waitFor()
//var appName = "War Robots";
//launchApp(appName);
//sleep(10000);
// 请求截图
var pngpath = "/sdcard/wwr/";
var targetpngath = "/sdcard/Pictures/"
var color1="#55FFBD";
if (!requestScreenCapture(1)) {
    toast("请求截图失败");
    exit();
}
//主界面开始战斗
var targetimg1 = $images.read(targetpngath+"主界面前往战斗.png");
var targetimg2 = $images.read(targetpngath+"模式选择前往战斗.png")

var targetpoint = (0,0);

targetpoint = FindTarget(targetimg1,0);
if(targetpoint){
    click(targetpoint.x+50,targetpoint.y+50);
    sleep(3000);
}else{
    toastLog("未找到该点");
}


targetpoint = FindTarget(color1,1);
click(targetpoint.x+50,targetpoint.y+50);

targetpoint = FindTarget(targetimg2,0);
click(targetpoint.x+50,targetpoint.y+50);



targetimg1.recycle();
targetimg2.recycle();

exit();


function FindTarget(arg,index) {
    captureScreen(pngpath+"main.png");
    var screenshots = $images.read(pngpath+"main.png");
    if(screenshots==null){
        toastLog("读取的截屏图片为空");
        return null;
    }
    if(index == 0){
        var p = findImage(screenshots, arg);
    }else{
        var p = findColor(screenshots, arg);
    }
    screenshots.recycle();
    return p;
}
